home *** CD-ROM | disk | FTP | other *** search
- Path: chaos.kulnet.kuleuven.ac.be!usenet
- From: Andreas De Troy <Andreas.DeTroy@ped.kuleuven.ac.be>
- Newsgroups: comp.lang.c
- Subject: Re: Please help me elect rounding of int division
- Date: 26 Feb 1996 09:09:00 GMT
- Organization: KUL
- Message-ID: <4grtbc$t9f@chaos.kulnet.kuleuven.ac.be>
- NNTP-Posting-Host: pcip194.psy.kuleuven.ac.be
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.2N (Windows; I; 16bit)
-
- news:4gq83r$omb@solutions.solon.com
- swedecj@vcnet.com (Carl Jacobson) wrote:
- >xmsb@shadow.borland.com (Maurice S. Barnum) wrote:
- >
- >>swedecj@vcnet.com (Carl Jacobson) writes:
- >
- >>>Please help me solve this task.
- >
- >>>I have now tried (Borland C++ version 3.0) for two solid days to write
- >>>a function that would allow me to round the quotient of (a/b) up or
- >>>down based on the "nearest" integer instead of being truncated to the
- >>>smallest.
-
- How about this:
-
- #include <float.h>
-
- long rounddiv (long a, long b)
- {
- return ((long) (floor (((float) a / b) + 0.5)));
- }
-
- It uses floating point, of course.
-
-